home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Source / SkelCmdPeriod.c < prev    next >
Text File  |  1996-01-17  |  2KB  |  73 lines

  1. /*
  2.  * SkelCmdPeriod.c -- Figure out, in an internationally compatible way, whether
  3.  * an event is a command-period key event.
  4.  *
  5.  * See TN TE 23, International Cancelling, for the rationale on how this works.
  6.  */
  7.  
  8. # include    <Script.h>
  9.  
  10. # include    "TransSkel.h"
  11.  
  12.  
  13. # define    kMaskModifiers    0xfe00
  14. # define    kMaskVirtualKey    0x0000ff00
  15. # define    kMaskAscii1        0x00ff0000
  16. # define    kMaskAscii2        0x000000ff
  17. # define    period            '.'
  18.  
  19.  
  20. pascal Boolean
  21. SkelCmdPeriod (EventRecord *evt)
  22. {
  23. short    keyCode;
  24. long    virtualKey;
  25. long    keyCId;
  26. long    keyInfo;
  27. # if skelUnivHeaders >= 2 && skelUnivHeadersMinor > 0
  28. unsigned long    state;
  29. # else
  30. long    state;
  31. # endif
  32. long    lowChar, highChar;
  33. Handle    hKCHR;
  34.  
  35.     if (evt->what == keyDown || evt->what == autoKey)
  36.     {
  37.         if (evt->modifiers & cmdKey)            /* cmd key is down */
  38.         {
  39.             /* find out ASCII equivalent for key */
  40.             virtualKey = (evt->message & kMaskVirtualKey) >> 8;
  41.             /* "and" out command key, "or" in the virtual key */
  42.             keyCode = (evt->modifiers & kMaskModifiers) | virtualKey;
  43. #if skelUnivHeaders
  44.             keyCId = GetScript (GetScriptManagerVariable (smKeyScript), smScriptKeys);
  45. #else
  46.             /* can't use new name for this one in non-universal headers */
  47.             keyCId = GetScript (GetEnvirons (smKeyScript), smScriptKeys);
  48. #endif
  49.             hKCHR = GetResource ('KCHR', keyCId);
  50.             if (hKCHR != (Handle) nil)
  51.             {
  52.                 state = 0;
  53.                 /*
  54.                  * Don't bother locking because KeyTrans doesn't move memory.
  55.                  * If you get a prototype error on the next line, it's probably
  56.                  * because skelUnivHeadersMinor wasn't computed properly in
  57.                  * TransSkel.h and thus the type for state wasn't determined
  58.                  * correctly.
  59.                  */
  60.                 keyInfo = KeyTranslate (*hKCHR, keyCode, &state);
  61.                 ReleaseResource (hKCHR);
  62.             }
  63.             else
  64.                 keyInfo = evt->message;
  65.  
  66.             lowChar = keyInfo & kMaskAscii2;
  67.             highChar = (keyInfo & kMaskAscii1) >> 16;
  68.             if (lowChar == period || highChar == period)
  69.                 return (true);
  70.         }
  71.     }
  72.     return (false);
  73. }